<template>
  <star-horse-dialog :title = "dialogTitle" :visible = "batchDialogTableVisible" @merge = "merge"
                     @mergeDraft = "mergeDraft"
                     @reset = "resetForm"
                     is-batch = "true">
    <el-form :model = "ruleForm" :rules = "rules" class = "demo-ruleForm" ref = "ruleForm">
      <el-table
          :data = "ruleForm.batchDataList"
          :row-class-name = "rowClassName"
          @selection-change = "handleDetailSelectionChange"
          border
          fit = "true"
          ref = "tb"
          v-loading = "loading"
      >
        <el-table-column align = "center" fixed = "left" type = "selection" width = "30"/>
        <el-table-column align = "center" label = "序号" prop = "xh" width = "50"></el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "db授权主键"
            min-width = "200px"
            prop = "idDbAssign"
            sortable
            v-if = " false ">
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.idDbAssign'" :rules = "rules.idDbAssign"
                          required>
              <el-select clearable placeholder = "请选择状态" v-model = "scope.row.statusCode">
                <el-option
                    :key = "sitem.statusCode"
                    :label = "sitem.statusName"
                    :value = "sitem.statusCode"
                    v-for = "sitem in selectData"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "数据库配置信息编号"
            min-width = "200px"
            prop = "dbinfoSingle"
            sortable
            v-if = "true ">
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.dbinfoSingle'" :rules = "rules.dbinfoSingle"
                          required>
              <el-select clearable placeholder = "请选择状态" v-model = "scope.row.statusCode">
                <el-option
                    :key = "sitem.statusCode"
                    :label = "sitem.statusName"
                    :value = "sitem.statusCode"
                    v-for = "sitem in selectData"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "被授权人编号"
            min-width = "200px"
            prop = "assignNo"
            sortable
            v-if = "true ">
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.assignNo'" :rules = "rules.assignNo"
                          required>
              <el-select clearable placeholder = "请选择状态" v-model = "scope.row.statusCode">
                <el-option
                    :key = "sitem.statusCode"
                    :label = "sitem.statusName"
                    :value = "sitem.statusCode"
                    v-for = "sitem in selectData"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "授权类型 1 按用户授权 2 按角色授权 默认 1"
            min-width = "200px"
            prop = "assignType"
            sortable
            v-if = "true ">
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.assignType'" :rules = "rules.assignType"
                          required>
              <el-select clearable placeholder = "请选择状态" v-model = "scope.row.statusCode">
                <el-option
                    :key = "sitem.statusCode"
                    :label = "sitem.statusName"
                    :value = "sitem.statusCode"
                    v-for = "sitem in selectData"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "操作人"
            min-width = "200px"
            prop = "operator"
            sortable
            v-if = "true ">
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.operator'" :rules = "rules.operator"
                          required>
              <el-select clearable placeholder = "请选择状态" v-model = "scope.row.statusCode">
                <el-option
                    :key = "sitem.statusCode"
                    :label = "sitem.statusName"
                    :value = "sitem.statusCode"
                    v-for = "sitem in selectData"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "被授权人操作范围"
            min-width = "200px"
            prop = "operatorRange"
            sortable
            v-if = "true ">
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.operatorRange'"
                          :rules = "rules.operatorRange" required>
              <el-select clearable placeholder = "请选择状态" v-model = "scope.row.statusCode">
                <el-option
                    :key = "sitem.statusCode"
                    :label = "sitem.statusName"
                    :value = "sitem.statusCode"
                    v-for = "sitem in selectData"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "授权描述"
            min-width = "200px"
            prop = "assginDesc"
            sortable
            v-if = "true ">
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.assginDesc'" :rules = "rules.assginDesc"
                          required>
              <el-select clearable placeholder = "请选择状态" v-model = "scope.row.statusCode">
                <el-option
                    :key = "sitem.statusCode"
                    :label = "sitem.statusName"
                    :value = "sitem.statusCode"
                    v-for = "sitem in selectData"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "授权生效日期"
            min-width = "200px"
            prop = "effectiveDate"
            sortable
            v-if = "true ">
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.effectiveDate'"
                          :rules = "rules.effectiveDate" required>
              <el-date-picker clearable placeholder = "请选择授权生效日期"
                              type = "date"
                              v-model = "scope.row.effectiveDate">
              </el-date-picker>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "授权失效日期"
            min-width = "200px"
            prop = "expiredDate"
            sortable
            v-if = "true ">
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.expiredDate'" :rules = "rules.expiredDate"
                          required>
              <el-date-picker clearable placeholder = "请选择授权失效日期"
                              type = "date"
                              v-model = "scope.row.expiredDate">
              </el-date-picker>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "修改人"
            min-width = "200px"
            prop = "updatedBy"
            sortable
            v-if = " false ">
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.updatedBy'" :rules = "rules.updatedBy">
              <el-select clearable placeholder = "请选择状态" v-model = "scope.row.statusCode">
                <el-option
                    :key = "sitem.statusCode"
                    :label = "sitem.statusName"
                    :value = "sitem.statusCode"
                    v-for = "sitem in selectData"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "修改日期"
            min-width = "200px"
            prop = "updatedDate"
            sortable
            v-if = " false ">
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.updatedDate'" :rules = "rules.updatedDate">
              <el-date-picker clearable placeholder = "请选择修改日期"
                              type = "date"
                              v-model = "scope.row.updatedDate">
              </el-date-picker>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "创建人"
            min-width = "200px"
            prop = "createdBy"
            sortable
            v-if = " false ">
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.createdBy'" :rules = "rules.createdBy">
              <el-select clearable placeholder = "请选择状态" v-model = "scope.row.statusCode">
                <el-option
                    :key = "sitem.statusCode"
                    :label = "sitem.statusName"
                    :value = "sitem.statusCode"
                    v-for = "sitem in selectData"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "创建日期"
            min-width = "200px"
            prop = "createdDate"
            sortable
            v-if = " false ">
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.createdDate'" :rules = "rules.createdDate">
              <el-date-picker clearable placeholder = "请选择创建日期"
                              type = "date"
                              v-model = "scope.row.createdDate">
              </el-date-picker>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "是否删除 1 是 0否"
            min-width = "200px"
            prop = "isDel"
            sortable
            v-if = " false ">
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.isDel'" :rules = "rules.isDel">
              <el-select clearable placeholder = "请选择状态" v-model = "scope.row.statusCode">
                <el-option
                    :key = "sitem.statusCode"
                    :label = "sitem.statusName"
                    :value = "sitem.statusCode"
                    v-for = "sitem in selectData"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "状态名称"
            min-width = "200px"
            prop = "statusName"
            sortable
            v-if = " false ">
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.statusName'" :rules = "rules.statusName">
              <el-select clearable placeholder = "请选择状态" v-model = "scope.row.statusCode">
                <el-option
                    :key = "sitem.statusCode"
                    :label = "sitem.statusName"
                    :value = "sitem.statusCode"
                    v-for = "sitem in selectData"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "状态编码"
            min-width = "200px"
            prop = "statusCode"
            sortable
            v-if = "true ">
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.statusCode'" :rules = "rules.statusCode"
                          required>
              <el-input clearable placeholder = "请输入状态编码"
                        v-model = "scope.row.statusCode"></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "数据编号"
            min-width = "200px"
            prop = "dataNo"
            sortable
            v-if = " false ">
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.dataNo'" :rules = "rules.dataNo">
              <el-select clearable placeholder = "请选择状态" v-model = "scope.row.statusCode">
                <el-option
                    :key = "sitem.statusCode"
                    :label = "sitem.statusName"
                    :value = "sitem.statusCode"
                    v-for = "sitem in selectData"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column fixed = "right" label = "操作" min-width = "150px">
          <template #header = "scope">
            <span>操作</span>&nbsp;&nbsp;
            <el-button @click = "handleAddDetails(scope.row,1)" link size = "mini" type = "primary">
              <el-tooltip content = "添加一行">
                <user-icon icon = "plus" style = "vertical-align: middle;color:#409EFF;"/>
              </el-tooltip>
            </el-button>
          </template>
          <template #default = "scope">
            <el-button @click = "handleAddDetails(scope.row,1)" link size = "mini" type = "primary">
              <el-tooltip content = "添加一行">添加</el-tooltip>
            </el-button>
            <el-button @click = "handleAddDetails(scope.row,2)" link size = "mini" type = "danger">
              <el-tooltip content = "删除当前行">删除</el-tooltip>
            </el-button>
          </template>
        </el-table-column>
      </el-table>

    </el-form>
  </star-horse-dialog>

  <star-horse-dialog :title = "dialogTitle" :visible = "dialogTableVisible" @merge = "merge" @mergeDraft = "mergeDraft"
                     @reset = "resetForm">
    <el-form :model = "ruleForm" :rules = "rules" class = "demo-ruleForm" ref = "ruleForm">
      <el-form-item label = "db授权主键" prop = "idDbAssign" v-if = "false">
        <el-input clearable placeholder = "请输入db授权主键"
                  v-model = "ruleForm.idDbAssign"></el-input>
      </el-form-item>
      <el-row>
        <el-col :span = "10">
          <el-form-item label = "授权数据库" prop = "dbinfoSingle"
                        required v-if = "!false">
            <el-select clearable
                       filterable
                       placeholder = "请选择数据库信息"
                       v-model = "ruleForm.dbinfoSingle"
            >
              <el-option
                  :key = "sitem.dataNo"
                  :label = "sitem.dbType+':'+sitem.host+'/'+sitem.dbName"
                  :value = "sitem.dataNo"
                  v-for = "sitem in dbList"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span = "14">
          <el-form-item label = "被授权人操作范围" prop = "operatorRangeList"
                        required v-if = "!false">

            <el-select clearable
                       filterable
                       multiple
                       placeholder = "请选择可操作范围"
                       v-model = "ruleForm.operatorRangeList"
            >
              <el-option
                  :key = "sitem.value"
                  :label = "sitem.name"
                  :value = "sitem.value"
                  v-for = "sitem in sqlLangs"
              >
              </el-option>
            </el-select>

          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span = "12">
          <el-form-item label = "授权类型 " prop = "assignType"
                        required v-if = "!false">
            <el-select @change = "getUserOrRole" clearable placeholder = "请选择状授权类型" ref = "assignType"
                       v-model = "ruleForm.assignType">
              <el-option
                  :key = "sitem.value"
                  :label = "sitem.name"
                  :value = "sitem.value"
                  v-for = "sitem in assignType"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span = "12">
          <el-form-item :label = "ruleForm.assignType==1?'被授权人账号':'被授权角色'" prop = "assignNo"
                        required v-if = "!false">
            <el-select :placeholder = "ruleForm.assignType==1?'请选择被授权人账号':'请选择被授权角色'"
                       :remote-method = "searchUserOrRole"
                       clearable
                       filterable
                       remote reserve-keyword
                       v-model = "ruleForm.assignNo">
              <el-option
                  :key = "sitem.value"
                  :label = "sitem.name"
                  :value = "sitem.value"
                  v-for = "sitem in userOrRoleList"
              >
              </el-option>
            </el-select>

          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span = "12">
          <el-form-item label = "经办人" prop = "operator"
                        required v-if = "!false">
            <el-input clearable placeholder = "请输入经办人"
                      v-model = "ruleForm.operator"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span = "12">
          <el-form-item label = "状态" prop = "statusCode"
                        required v-if = "!false">
            <el-select placeholder = "请选择状态" v-model = "ruleForm.statusCode">
              <el-option
                  :key = "sitem.statusCode"
                  :label = "sitem.statusName"
                  :value = "sitem.statusCode"
                  clearable
                  v-for = "sitem in selectData"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span = "12">
          <el-form-item label = "授权生效日期" prop = "effectiveDate"
                        required v-if = "!false">
            <el-date-picker clearable placeholder = "请选择授权生效日期" type = "date"
                            v-model = "ruleForm.effectiveDate">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span = "12">
          <el-form-item label = "授权失效日期" prop = "expiredDate"
                        required v-if = "!false">
            <el-date-picker clearable placeholder = "请选择授权失效日期" type = "date"
                            v-model = "ruleForm.expiredDate">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>


      <el-form-item label = "授权描述" prop = "assginDesc"
                    required v-if = "!false">
        <el-input clearable placeholder = "请输入授权描述" type = "textarea"
                  v-model = "ruleForm.assginDesc"></el-input>
      </el-form-item>


      <el-form-item label = "修改人" prop = "updatedBy"
                    v-if = "!true">
        <el-input clearable placeholder = "请输入修改人"
                  v-model = "ruleForm.updatedBy"></el-input>
      </el-form-item>

      <el-form-item label = "修改日期" prop = "updatedDate"
                    v-if = "!true">
        <el-date-picker clearable placeholder = "请选择修改日期" type = "date"
                        v-model = "ruleForm.updatedDate">
        </el-date-picker>
      </el-form-item>

      <el-form-item label = "创建人" prop = "createdBy"
                    v-if = "!true">
        <el-input clearable placeholder = "请输入创建人"
                  v-model = "ruleForm.createdBy"></el-input>
      </el-form-item>

      <el-form-item label = "创建日期" prop = "createdDate"
                    v-if = "!true">
        <el-date-picker clearable placeholder = "请选择创建日期" type = "date"
                        v-model = "ruleForm.createdDate">
        </el-date-picker>
      </el-form-item>

      <el-form-item label = "是否删除 1 是 0否" prop = "isDel"
                    v-if = "!true">
        <el-input-number clearable placeholder = "请输入是否删除 1 是 0否"
                         v-model = "ruleForm.isDel"/>
      </el-form-item>

      <el-form-item label = "状态名称" prop = "statusName"
                    v-if = "!true">
        <el-input clearable placeholder = "请输入状态名称"
                  v-model = "ruleForm.statusName"></el-input>
      </el-form-item>


      <el-form-item label = "数据编号" prop = "dataNo"
                    v-if = "!true">
        <el-input clearable placeholder = "请输入数据编号"
                  v-model = "ruleForm.dataNo"></el-input>
      </el-form-item>

    </el-form>
  </star-horse-dialog>
  <star-horse-dialog :is-view = "true" :title = "'查看数据'" :visible = "viewVisible">
    <el-form :model = "ruleForm" class = "view-ruleForm" label-width = "15%" ref = "ruleForm">
      <el-form-item label = "db授权主键" prop = "idDbAssign" v-if = "false">
        <span>{{ ruleForm.idDbAssign }}</span>
      </el-form-item>
      <el-form-item label = "数据库配置信息" prop = "dbinfoSingle">
        <span>{{ ruleForm.dbinfoSingle }}</span>
      </el-form-item>
      <el-form-item label = "被授权人编号" prop = "assignNo">
        <span>{{ ruleForm.assignNo }}</span>
      </el-form-item>
      <el-form-item label = "授权类型 1 按用户授权 2 按角色授权 默认 1" prop = "assignType">
        <span>{{ ruleForm.assignType }}</span>
      </el-form-item>
      <el-form-item label = "操作人" prop = "operator">
        <span>{{ ruleForm.operator }}</span>
      </el-form-item>
      <el-form-item label = "被授权人操作范围" prop = "operatorRange">
        <span>{{ ruleForm.operatorRange }}</span>
      </el-form-item>
      <el-form-item label = "授权描述" prop = "assginDesc">
        <span>{{ ruleForm.assginDesc }}</span>
      </el-form-item>
      <el-form-item label = "授权生效日期" prop = "effectiveDate">
        <span>{{ ruleForm.effectiveDate }}</span>
      </el-form-item>
      <el-form-item label = "授权失效日期" prop = "expiredDate">
        <span>{{ ruleForm.expiredDate }}</span>
      </el-form-item>
      <el-form-item label = "修改人" prop = "updatedBy">
        <span>{{ ruleForm.updatedBy }}</span>
      </el-form-item>
      <el-form-item label = "修改日期" prop = "updatedDate">
        <span>{{ ruleForm.updatedDate }}</span>
      </el-form-item>
      <el-form-item label = "创建人" prop = "createdBy">
        <span>{{ ruleForm.createdBy }}</span>
      </el-form-item>
      <el-form-item label = "创建日期" prop = "createdDate">
        <span>{{ ruleForm.createdDate }}</span>
      </el-form-item>
      <el-form-item label = "是否删除 1 是 0否" prop = "isDel" v-if = "false">
        <span>{{ ruleForm.isDel }}</span>
      </el-form-item>
      <el-form-item label = "状态名称" prop = "statusName">
        <span>{{ ruleForm.statusName }}</span>
      </el-form-item>
      <el-form-item label = "状态编码" prop = "statusCode" v-if = "false">
        <span>{{ ruleForm.statusCode }}</span>
      </el-form-item>
      <el-form-item label = "数据编号" prop = "dataNo">
        <span>{{ ruleForm.dataNo }}</span>
      </el-form-item>
    </el-form>
  </star-horse-dialog>
  <el-card>
    <el-form class = "search_area" size = "default">
      <el-form-item label = "数据库类型">
        <el-input placeholder = "请输入数据库类型" v-model = "searchForm.dbType"/>
      </el-form-item>
      <el-form-item label = "数据库名称">
        <el-input placeholder = "请输入数据库名称" v-model = "searchForm.dbname"/>
      </el-form-item>
      <el-form-item label = "被授权用户/角色">
        <el-input placeholder = "请输入授权用户/角色" v-model = "searchForm.assignNo"/>
      </el-form-item>
      <el-form-item label = "权限范围">
        <el-input placeholder = "请输入权限范围" v-model = "searchForm.operatorRange"/>
      </el-form-item>
      <el-form-item label = "添加时间">
        <el-date-picker
            end-placeholder = "结束日期" placeholder = "请选择添加时间"
            range-separator = "到"
            start-placeholder = "开始日期"
            type = "daterange"
            v-model = "searchForm.createdDate"
        />
      </el-form-item>
      <el-form-item label = "     ">
        <el-button @click = "dataSearch" link type = "primary">
          <user-icon icon = "search"/>
          <span style = "vertical-align: middle;"> 查询 </span>
        </el-button>
        <el-button @click = "dataSearch(1)" link small>
          <span style = "vertical-align: middle;"> 重置 </span>
        </el-button>
      </el-form-item>
    </el-form>
    <el-divider/>
    <ul class = "inner_button">
      <li v-if = "permission.add">
        <el-button @click = "btnOperation(1)" link title = "" type = "primary">
          <user-icon icon = "plus"/>
          <el-tooltip content = "新增">新增</el-tooltip>
        </el-button>
      </li>
      <li v-if = "permission.batchAdd">
        <el-button @click = "btnOperation(11)" link title = "" type = "primary">
          <user-icon icon = "plus-square"/>
          <el-tooltip content = "批量新增">批量新增</el-tooltip>
        </el-button>
      </li>

      <li v-if = "permission.delete">
        <el-button @click = "btnOperation(4)" link title = "" type = "danger">
          <user-icon icon = "minus-square"/>
          <el-tooltip content = "批量删除">批量删除</el-tooltip>
        </el-button>
      </li>
      <li v-if = "permission.view">
        <el-button @click = "btnOperation(5)" link title = "" type = "primary">
          <user-icon icon = "sync"/>
          <el-tooltip content = "刷新">刷新</el-tooltip>

        </el-button>
      </li>
      <li v-if = "permission.download">
        <el-button @click = "btnOperation(6)" link title = "" type = "primary">
          <user-icon icon = "file-download"/>
          <el-tooltip content = "下载模板">下载模板</el-tooltip>
        </el-button>
      </li>
      <li v-if = "permission.execution">
        <el-button @click = "btnOperation(7)" link title = "" type = "primary">
          <user-icon icon = "play-circle"/>
          <el-tooltip content = "执行">执行</el-tooltip>
        </el-button>
      </li>
      <li v-if = "permission.upload">
        <el-upload
            :auto-upload = "true"
            :on-change = "upload"
            :on-error = "uploadError"
            :on-progress = "uploadProcess"
            :on-success = "uploadSuccess"
            :show-file-list = "false"
            action = "/system-config/system/dbAssign/importData"
            class = "upload-demo"
            name = "file"
        >
          <el-button link title = "" type = "primary">
            <user-icon icon = "file-upload"/>
            <el-tooltip content = "上传">上传</el-tooltip>
          </el-button>

        </el-upload>
      </li>
      <li v-if = "permission.export">
        <el-button @click = "btnOperation(8)" link title = "" type = "primary">
          <user-icon icon = "file-export"/>
          <el-tooltip content = "导出">导出</el-tooltip>
        </el-button>
      </li>
    </ul>
    <el-table
        :data = "dataList"
        :row-key = "getRowIdentity"
        @row-dblclick = "editData"
        @selection-change = "handleSelectionChange"
        border
        class = "data_table"
        fit = "true"
        highlight-current-row = "true"
        id = "GrantPermissionTable"
        max-height = "470px"
        ref = "multipleTable"
        stripe = "true">
      <el-table-column fixed width = "1"/>
      <el-table-column
          :reserve-selection = "true"
          align = "center"
          fixed = "left"
          type = "selection"
      />
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "db授权主键"
          min-width = "200px"
          prop = "idDbAssign"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "数据库配置信息"
          min-width = "200px"
          prop = "dbinfoSingle"
          sortable
          v-if = "true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "被授权人账号/角色"
          min-width = "200px"
          prop = "assignNo"
          sortable
          v-if = "true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "授权类型"
          min-width = "200px"
          prop = "assignType"
          sortable
          v-if = "true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "操作人"
          min-width = "200px"
          prop = "operator"
          sortable
          v-if = "true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "被授权人操作范围"
          min-width = "200px"
          prop = "operatorRange"
          sortable
          v-if = "true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "授权描述"
          min-width = "200px"
          prop = "assginDesc"
          sortable
          v-if = "true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "授权生效日期"
          min-width = "200px"
          prop = "effectiveDate"
          sortable
          v-if = "true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "授权失效日期"
          min-width = "200px"
          prop = "expiredDate"
          sortable
          v-if = "true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "修改人"
          min-width = "200px"
          prop = "updatedBy"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "修改日期"
          min-width = "200px"
          prop = "updatedDate"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "创建人"
          min-width = "200px"
          prop = "createdBy"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "创建日期"
          min-width = "200px"
          prop = "createdDate"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "是否删除 1 是 0否"
          min-width = "200px"
          prop = "isDel"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "状态名称"
          min-width = "200px"
          prop = "statusName"
          sortable
          v-if = "true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "状态编码"
          min-width = "200px"
          prop = "statusCode"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "数据编号"
          min-width = "200px"
          prop = "dataNo"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column fixed = "right" label = "操作" min-width = "180px">
        <template #default = "scope">
          <el-button @click = "editById(scope.row[primaryKey])" link title = "" type = "primary"
                     v-if = "permission.edit">
            <el-tooltip content = "编辑">编辑</el-tooltip>
          </el-button>
          <el-button @click = "viewById(scope.row[primaryKey])" link title = "" type = "primary"
                     v-if = "permission.view">
            <el-tooltip content = "查看">查看</el-tooltip>
          </el-button>
          <el-button @click = "deleteById(scope.row[primaryKey])" link title = "" type = "danger"
                     v-if = "permission.delete">
            <el-tooltip content = "删除">删除</el-tooltip>
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-divider/>
    <el-pagination
        :total = "totalData"
        @current-change = "pageChangeClick"
        @size-change = "pageSizeClick"
        layout = "total, sizes, prev, pager, next, jumper"
        v-model:currentPage = "currentPage"
        v-model:page-size = "pageSize"
        v-model:pageCount = "totalPage"/>
  </el-card>
</template>
<style>

</style>
<script>
import {warning} from "../../utils/message";
import {getRequest, postRequest} from "../../api/star_horse";
import {getUserInfo} from "../../utils/auth";

import {common} from "../../api/common";
import {ref} from "vue";

export default {
  name: "GrantPermission",

  mixins: [common],
  setup() {
    return {}
  },
  data() {
    const loadByPageUrl = ref("/system-config/system/dbAssign/pageList");
    const mergeUrl = ref("/system-config/system/dbAssign/merge");
    const mergeDraftUrl = ref("/system-config/system/dbAssign/mergeDraft");
    const batchMergeUrl = ref("/system-config/system/dbAssign/mergeBatch");
    const batchMergeDraftUrl = ref("/system-config/system/dbAssign/mergeBatchDraft");
    const loadByIdUrl = ref("/system-config/system/dbAssign/getById");
    const deleteUrl = ref("/system-config/system/dbAssign/batchDeleteByIdLogic");
    const exportAllUrl = ref("/system-config/system/dbAssign/exportData");
    const downloadTemplateUrl = ref("/system-config/system/dbAssign/downloadTemplate");
    const primaryKey = "idDbAssign";
    return {
      loadByPageUrl,
      mergeUrl,
      mergeDraftUrl,
      batchMergeUrl,
      batchMergeDraftUrl,
      loadByIdUrl,
      deleteUrl,
      exportAllUrl,
      downloadTemplateUrl,
      primaryKey,
      dbList: [],
      userOrRoleList: [],
      userInfo: getUserInfo(),
      sqlLangs: [],
      assignType: [{name: "按用户授权", value: 1}, {name: "按角色授权", value: 2}]
    }
  },
  methods: {
    searchUserOrRole(val) {
      const _this = this;
      let type = _this.ruleForm.assignType;
      if (!type) {
        warning("请先选择授权类型");
        _this.ruleForm.assignNo = "";
        _this.$refs.assignType.focus();
        return;
      }
      let obj = {"propertyName": type == 1 ? "name" : "roleName", "value": val, "operation": "lk"};
      _this.queryCondition(obj);
    },
    queryCondition(obj) {
      let _this = this;
      let type = _this.ruleForm.assignType;
      let cond = [{"propertyName": "isDel", "value": 0},
        {"propertyName": "statusCode", "value": 1}];
      if (obj) {
        cond.push(obj);
      }
      postRequest(`/system-config/system/${type == 1 ? "usersinfoEntity" : "rolesinfoEntity"}/getAllByCondition`,
          cond).then(res => {
        let temp = res.data.data;
        _this.userOrRoleList = [];
        if (type == 2) {
          temp.forEach((item, index) => {
            _this.userOrRoleList.push({name: item.roleName, value: item.roleCode});
          });
        } else {
          temp.forEach((item, index) => {
            _this.userOrRoleList.push({name: item.name, value: item.username});
          });
        }
      });
    },
    getUserOrRole() {
      const _this = this;
      _this.queryCondition();

    },
    initDbList: function () {
      const _this = this;
      postRequest("/system-config/dbsearch/dbinfoEntity/getAllByCondition",
          [{"propertyName": "isDel", "value": 0},
            {"propertyName": "statusCode", "value": 1}]).then(res => {
        _this.dbList = res.data.data;
      });
    },
    initSqlLang: function () {
      const _this = this;
      getRequest("/system-config/system/dbAssign/allSqlLang").then(res => {
        _this.sqlLangs = res.data.data;
      });
    },

    dataFormat(row, column, cellValue, index) {
      cellValue = this.commonDataFormat(row, column, cellValue, index);
      if (column.property == "assignType") {
        return cellValue == 1 ? "按用户授权" : "按角色授权";
      }
      if (column.property == "dbinfoSingle" && row.dbinfoRespDto) {
        return row.dbinfoRespDto["dbType"] + ":" + row.dbinfoRespDto["host"] + "/" + row.dbinfoRespDto["dbName"];
      }
      return cellValue;
    },


    /**
     * 初始化数据
     */
    init: function () {
      this.dataList = [];
      this.selectData = [];
      this.loadByPage(this.currentPage, this.pageSize);
      this.initDbList();
      this.initSqlLang();
      this.loadPermissionResources();
      this.commonSelectData("sys_db_assign");

    },

    parseSearchData: function () {
      let data = this.searchForm;
      let arr = [];

      if (data.operatorRange) {
        arr.push({
          propertyName: "operatorRange",
          value: data.operatorRange,
          operation: "lk"
        });
      }
      if (data.assignNo) {
        arr.push({
          propertyName: "assignNo",
          value: data.assignNo,
          operation: "lk"
        });
      }
      if (data.createdDate) {
        arr.push({
          propertyName: "createdDate",
          value: data.createdDate,
          operation: "bt"
        });
      }
      return arr;
    }

  },
  created() {
    this.init();
  }
}
</script>